package com.yuexunit.operationman.nbsy.module.SafeOperation.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.bumptech.glide.Glide;
import com.yuexunit.operationman.nbsy.R;
import com.yuexunit.operationman.nbsy.base.BaseKJActivity;
import com.yuexunit.operationman.nbsy.base.SubmitBean;
import com.yuexunit.operationman.nbsy.config.AppConfig;
import com.yuexunit.operationman.nbsy.module.SafeOperation.bean.SafeOperationBean;
import com.yuexunit.operationman.nbsy.module.SafeOperation.bean.SignBean;
import com.yuexunit.operationman.nbsy.module.SafeOperation.model.impl.SafeOperationModel;
import com.yuexunit.operationman.nbsy.module.SafeOperation.model.impl.SafeOperationSignModel;
import com.yuexunit.operationman.nbsy.module.SafeOperation.presenter.ISafeOperationPresenter;
import com.yuexunit.operationman.nbsy.module.SafeOperation.presenter.ISafeOperationSignPresenter;
import com.yuexunit.operationman.nbsy.module.SafeOperation.presenter.impl.SafeOperationPresenter;
import com.yuexunit.operationman.nbsy.module.SafeOperation.presenter.impl.SafeOperationSignPresenter;
import com.yuexunit.operationman.nbsy.module.SafeOperation.ui.view.ISafeOperationSignView;
import com.yuexunit.operationman.nbsy.module.SafeOperation.ui.view.ISafeOperationView;
import com.yuexunit.operationman.nbsy.widget.ActionSheetDialog;
import com.yuexunit.operationman.nbsy.widget.ClickDialog;
import com.yuexunit.operationman.nbsy.widget.LoadingDialog;
import com.yuexunit.operationman.nbsy.widget.LoginDialog;

import org.kymjs.kjframe.ui.ViewInject;
import org.kymjs.kjframe.utils.PreferenceHelper;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by work-jx on 2017/3/15.
 */
public class Act_SafeOperation_BeforeNarcosis extends BaseKJActivity implements ISafeOperationView, ISafeOperationSignView {
    @Bind(R.id.tv_patient_name)
    TextView tvPatientName;
    @Bind(R.id.tv_patient_sex)
    TextView tvPatientSex;
    @Bind(R.id.tv_patient_visitno)
    TextView tvPatientVisitno;
    @Bind(R.id.tv_patient_disease)
    TextView tvPatientDisease;
    @Bind(R.id.edt_so_bn_00_01)
    EditText edtSoBn0001;
    @Bind(R.id.radio_so_bn_01_01)
    RadioButton radioSoBn0101;
    @Bind(R.id.radio_so_bn_01_02)
    RadioButton radioSoBn0102;
    @Bind(R.id.radio_group_so_bn_01)
    RadioGroup radioGroupSoBn01;
    @Bind(R.id.radio_so_bn_02_01)
    RadioButton radioSoBn0201;
    @Bind(R.id.radio_so_bn_02_02)
    RadioButton radioSoBn0202;
    @Bind(R.id.radio_group_so_bn_02)
    RadioGroup radioGroupSoBn02;
    @Bind(R.id.radio_so_bn_03_01)
    RadioButton radioSoBn0301;
    @Bind(R.id.radio_so_bn_03_02)
    RadioButton radioSoBn0302;
    @Bind(R.id.radio_group_so_bn_03)
    RadioGroup radioGroupSoBn03;
    @Bind(R.id.radio_so_bn_04_01)
    RadioButton radioSoBn0401;
    @Bind(R.id.radio_so_bn_04_02)
    RadioButton radioSoBn0402;
    @Bind(R.id.radio_group_so_bn_04)
    RadioGroup radioGroupSoBn04;
    @Bind(R.id.radio_so_bn_05_01)
    RadioButton radioSoBn0501;
    @Bind(R.id.radio_so_bn_05_02)
    RadioButton radioSoBn0502;
    @Bind(R.id.radio_group_so_bn_05)
    RadioGroup radioGroupSoBn05;
    @Bind(R.id.radio_so_bn_06_01)
    RadioButton radioSoBn0601;
    @Bind(R.id.radio_so_bn_06_02)
    RadioButton radioSoBn0602;
    @Bind(R.id.radio_group_so_bn_06)
    RadioGroup radioGroupSoBn06;
    @Bind(R.id.radio_so_bn_07_01)
    RadioButton radioSoBn0701;
    @Bind(R.id.radio_so_bn_07_02)
    RadioButton radioSoBn0702;
    @Bind(R.id.radio_group_so_bn_07)
    RadioGroup radioGroupSoBn07;
    @Bind(R.id.radio_so_bn_08_01)
    RadioButton radioSoBn0801;
    @Bind(R.id.radio_so_bn_08_02)
    RadioButton radioSoBn0802;
    @Bind(R.id.radio_group_so_bn_08)
    RadioGroup radioGroupSoBn08;
    @Bind(R.id.radio_so_bn_09_01)
    RadioButton radioSoBn0901;
    @Bind(R.id.radio_so_bn_09_02)
    RadioButton radioSoBn0902;
    @Bind(R.id.radio_group_so_bn_09)
    RadioGroup radioGroupSoBn09;
    @Bind(R.id.radio_so_bn_10_01)
    RadioButton radioSoBn1001;
    @Bind(R.id.radio_so_bn_10_02)
    RadioButton radioSoBn1002;
    @Bind(R.id.radio_group_so_bn_10)
    RadioGroup radioGroupSoBn10;
    @Bind(R.id.radio_so_bn_11_01)
    RadioButton radioSoBn1101;
    @Bind(R.id.radio_so_bn_11_02)
    RadioButton radioSoBn1102;
    @Bind(R.id.radio_group_so_bn_11)
    RadioGroup radioGroupSoBn11;
    @Bind(R.id.radio_so_bn_12_01)
    RadioButton radioSoBn1201;
    @Bind(R.id.radio_so_bn_12_02)
    RadioButton radioSoBn1202;
    @Bind(R.id.radio_group_so_bn_12)
    RadioGroup radioGroupSoBn12;
    @Bind(R.id.radio_so_bn_13_01)
    RadioButton radioSoBn1301;
    @Bind(R.id.radio_so_bn_13_02)
    RadioButton radioSoBn1302;
    @Bind(R.id.radio_group_so_bn_13)
    RadioGroup radioGroupSoBn13;
    @Bind(R.id.radio_so_bn_14_01)
    RadioButton radioSoBn1401;
    @Bind(R.id.radio_so_bn_14_02)
    RadioButton radioSoBn1402;
    @Bind(R.id.radio_group_so_bn_14)
    RadioGroup radioGroupSoBn14;
    @Bind(R.id.radio_so_bn_15_01)
    RadioButton radioSoBn1501;
    @Bind(R.id.radio_so_bn_15_02)
    RadioButton radioSoBn1502;
    @Bind(R.id.radio_group_so_bn_15)
    RadioGroup radioGroupSoBn15;
    @Bind(R.id.radio_so_bn_16_01)
    RadioButton radioSoBn1601;
    @Bind(R.id.radio_so_bn_16_02)
    RadioButton radioSoBn1602;
    @Bind(R.id.radio_group_so_bn_16)
    RadioGroup radioGroupSoBn16;
    @Bind(R.id.edt_so_bn_17_01)
    EditText edtSoBn1701;

    //签名
    @Bind(R.id.img_so_sign_operation)
    ImageView imgSoSignOperation;
    @Bind(R.id.btn_so_sign_operation)
    TextView btnSoSignOperation;
    @Bind(R.id.tv_so_sign_operation_time)
    TextView tvSoSignOperationTime;
    @Bind(R.id.tv_so_sign_operation_name)
    TextView tvSoSignOperationName;

    ISafeOperationPresenter presenter;
    LoadingDialog loadingDialog;

    LoginDialog loginDialog;
    ISafeOperationSignPresenter presenter_sign;

    ClickDialog dialog;

    @Override
    public void setRootView() {
        setContentView(R.layout.act_safeoperation_beforenarcosis);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        super.initData();
        loginDialog = new LoginDialog(aty);
        loadingDialog = new LoadingDialog(this);
        presenter = new SafeOperationPresenter(this, new SafeOperationModel());
        presenter_sign = new SafeOperationSignPresenter(this, new SafeOperationSignModel());
        setTitle();
        setContent();
    }

    private void setTitle() {
        tvPatientName.setText(AppConfig.SAFEOPERATIONBEAN.getObject().getSecurity().getPatientName());
        if (AppConfig.SAFEOPERATIONBEAN.getObject().getSecurity().getPatientSex().equals("1")) {
            tvPatientSex.setText("男");
        } else if (AppConfig.SAFEOPERATIONBEAN.getObject().getSecurity().getPatientSex().equals("2")) {
            tvPatientSex.setText("女");
        } else {
            tvPatientSex.setText("不详");
        }
        tvPatientVisitno.setText("住院号" + AppConfig.SAFEOPERATIONBEAN.getObject().getSecurity().getInHospitalNo());
        tvPatientDisease.setText(AppConfig.SAFEOPERATIONBEAN.getObject().getSecurity().getOperandi());
    }

    private void setContent() {
        if (AppConfig.SAFEOPERATIONBEAN.getObject().getSecurity().getOperationSign() != null) {
            imgSoSignOperation.setVisibility(View.VISIBLE);
            btnSoSignOperation.setVisibility(View.GONE);
            tvSoSignOperationTime.setVisibility(View.VISIBLE);
            tvSoSignOperationName.setVisibility(View.VISIBLE);
            Glide.with(aty)
                    .load(AppConfig.SAFEOPERATIONBEAN.getObject().getSecurity().getOperationSignUrl())
                    .placeholder(R.color.white)
                    .error(R.color.white)
                    .into(imgSoSignOperation);
            tvSoSignOperationTime.setText("签名时间:" + AppConfig.SAFEOPERATIONBEAN.getObject().getSecurity().getOperationSignTimeStr());
            tvSoSignOperationName.setText(AppConfig.SAFEOPERATIONBEAN.getObject().getSecurity().getOperationSign());
        }

        edtSoBn0001.setText(AppConfig.SAFEOPERATIONBEAN.getObject().getSecurity().getAnesthesia());
        for (SafeOperationBean.ObjectEntity.SecurityItemListEntity p : AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList()) {
            switch (p.getItemCode()) {
                case "MZ_HuanZheXinXi":
                    if (p.getItemValue().equals("1")) {
                        radioSoBn0101.setChecked(true);
                    } else if (p.getItemValue().equals("0")) {
                        radioSoBn0102.setChecked(true);
                    }
                    break;
                case "MZ_ShouShuFangShi":
                    if (p.getItemValue().equals("1")) {
                        radioSoBn0201.setChecked(true);
                    } else if (p.getItemValue().equals("0")) {
                        radioSoBn0202.setChecked(true);
                    }
                    break;
                case "MZ_ShouShuBuWei":
                    if (p.getItemValue().equals("1")) {
                        radioSoBn0301.setChecked(true);
                    } else if (p.getItemValue().equals("0")) {
                        radioSoBn0302.setChecked(true);
                    }
                    break;
                case "MZ_ShouShuZhiQing":
                    if (p.getItemValue().equals("1")) {
                        radioSoBn0401.setChecked(true);
                    } else if (p.getItemValue().equals("0")) {
                        radioSoBn0402.setChecked(true);
                    }
                    break;
                case "MZ_MaZuiZhiQing":
                    if (p.getItemValue().equals("1")) {
                        radioSoBn0501.setChecked(true);
                    } else if (p.getItemValue().equals("0")) {
                        radioSoBn0502.setChecked(true);
                    }
                    break;
                case "MZ_MaZuiFangShi":
                    if (p.getItemValue().equals("1")) {
                        radioSoBn0601.setChecked(true);
                    } else if (p.getItemValue().equals("0")) {
                        radioSoBn0602.setChecked(true);
                    }
                    break;
                case "MZ_MaZuiSheBeiAnQuan":
                    if (p.getItemValue().equals("1")) {
                        radioSoBn0701.setChecked(true);
                    } else if (p.getItemValue().equals("0")) {
                        radioSoBn0702.setChecked(true);
                    }
                    break;
                case "MZ_PiFuWanZheng":
                    if (p.getItemValue().equals("1")) {
                        radioSoBn0801.setChecked(true);
                    } else if (p.getItemValue().equals("0")) {
                        radioSoBn0802.setChecked(true);
                    }
                    break;
                case "MZ_ShuQianPiFuZhunBei":
                    if (p.getItemValue().equals("1")) {
                        radioSoBn0901.setChecked(true);
                    } else if (p.getItemValue().equals("0")) {
                        radioSoBn0902.setChecked(true);
                    }
                    break;
                case "MZ_JingMaiTongDaoJianLi":
                    if (p.getItemValue().equals("1")) {
                        radioSoBn1001.setChecked(true);
                    } else if (p.getItemValue().equals("0")) {
                        radioSoBn1002.setChecked(true);
                    }
                    break;
                case "MZ_HuanZheGuoMingShi":
                    if (p.getItemValue().equals("1")) {
                        radioSoBn1101.setChecked(true);
                    } else if (p.getItemValue().equals("0")) {
                        radioSoBn1102.setChecked(true);
                    }
                    break;
                case "MZ_KangJunYaoWuPiShi":
                    if (p.getItemValue().equals("1")) {
                        radioSoBn1201.setChecked(true);
                    } else if (p.getItemValue().equals("0")) {
                        radioSoBn1202.setChecked(true);
                    }
                    break;
                case "MZ_ShuQianBeiXue":
                    if (p.getItemValue().equals("1")) {
                        radioSoBn1301.setChecked(true);
                    } else if (p.getItemValue().equals("0")) {
                        radioSoBn1302.setChecked(true);
                    }
                    break;
                case "MZ_JiaTi":
                    if (p.getItemValue().equals("1")) {
                        radioSoBn1401.setChecked(true);
                    } else if (p.getItemValue().equals("0")) {
                        radioSoBn1402.setChecked(true);
                    }
                    break;
                case "MZ_TiNeiZhiRuWu":
                    if (p.getItemValue().equals("1")) {
                        radioSoBn1501.setChecked(true);
                    } else if (p.getItemValue().equals("0")) {
                        radioSoBn1502.setChecked(true);
                    }
                    break;
                case "MZ_YingXiangXueZiLiao":
                    if (p.getItemValue().equals("1")) {
                        radioSoBn1601.setChecked(true);
                    } else if (p.getItemValue().equals("0")) {
                        radioSoBn1602.setChecked(true);
                    }
                    break;
                case "MZ_Other":
                    edtSoBn1701.setText(p.getItemValue());
                    break;
            }
        }
    }

    @OnClick({R.id.titlebar_docadvice_img_back, R.id.so_bn_btn, R.id.btn_so_sign_operation})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.titlebar_docadvice_img_back:
                finish();
                break;
            case R.id.so_bn_btn:
                if(AppConfig.SAFEOPERATIONBEAN.getObject().getSecurity().getOperationSign()!=null) {
                    insertContent();
                }
                else {
                    dialog = new ClickDialog(aty).builder().setTxt("存在未签名,是否提交？");
                    dialog.isCancleBack(true);
                    dialog.setCallBack(new ClickDialog.ICallBack() {
                        @Override
                        public void callback(Bundle bundle) {
                            if(bundle.getInt("data") == 0){
                                insertContent();
                            } else if(bundle.getInt("data") == 1){
                                dialog.dismiss();
                            }

                        }
                    });
                    dialog.show();
                }
                break;
            case R.id.btn_so_sign_operation:
                showTypeDialog();
                break;
        }
    }

    private void showTypeDialog() {
        ActionSheetDialog actionSheetDialog;
        actionSheetDialog = new ActionSheetDialog(this).builder()
                .setCancelable(true)
                .setCanceledOnTouchOutside(true);
        actionSheetDialog.addSheetItem("HIS签名", ActionSheetDialog.SheetItemColor.Blue,
                new ActionSheetDialog.OnSheetItemClickListener() {
                    @Override
                    public void onClick(int which) {
                        loginDialog.builder();
                        loginDialog.show();
                        loginDialog.setCallBack(new LoginDialog.ICallBack() {
                            @Override
                            public void callback(Bundle bundle) {
                                Map<String, String> params = new HashMap<>();
                                params.put("jobNum", bundle.getString("person_num"));
                                params.put("loginPwd", bundle.getString("person_psw"));
                                presenter_sign.getSignInfo(params);
                            }
                        });
                    }
                });
        actionSheetDialog.addSheetItem("虹膜签名(暂不可用)", ActionSheetDialog.SheetItemColor.Blue,
                new ActionSheetDialog.OnSheetItemClickListener() {
                    @Override
                    public void onClick(int which) {

                    }
                });
        actionSheetDialog.show();
    }

    @Override
    public void getSignInfo(SignBean signBean) {
        loginDialog.dismiss();
        if (signBean.getCode() == 200) {
            if (signBean.getObject().getDoctorType().equals("Y")) {
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", java.util.Locale.getDefault());
                Date curDate = new Date(System.currentTimeMillis());//获取当前时间
                String str = formatter.format(curDate);
                imgSoSignOperation.setVisibility(View.VISIBLE);
                Glide.with(this)
                        .load(signBean.getObject().getSignPicture())
                        .placeholder(R.color.white)
                        .error(R.color.white)
                        .into(imgSoSignOperation);
                btnSoSignOperation.setVisibility(View.GONE);
                tvSoSignOperationTime.setVisibility(View.VISIBLE);
                tvSoSignOperationTime.setText("签名时间:" + str);
                tvSoSignOperationName.setVisibility(View.VISIBLE);
                tvSoSignOperationName.setText(signBean.getObject().getDoctorName());

                AppConfig.SAFEOPERATIONBEAN.getObject().getSecurity().setOperationSign(signBean.getObject().getDoctorName());
                AppConfig.SAFEOPERATIONBEAN.getObject().getSecurity().setOperationSignUrl(signBean.getObject().getSignPicture());
                AppConfig.SAFEOPERATIONBEAN.getObject().getSecurity().setOperationSignTimeStr(str);
            } else {
                ViewInject.toast("请使用医生账号进行签名");
            }
        } else {
            ViewInject.toast(signBean.getDesc());
        }
    }

    private void insertContent() {
        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurity().setAnesthesia(edtSoBn0001.getText().toString());
        for (int i = 0; i < AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().size(); i++) {
            String value = "";
            switch (AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).getItemCode()) {
                case "MZ_HuanZheXinXi":
                    if (radioSoBn0101.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("1");
                    } else if (radioSoBn0102.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("0");
                    } else {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("");
                    }
                    break;
                case "MZ_ShouShuFangShi":
                    if (radioSoBn0201.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("1");
                    } else if (radioSoBn0202.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("0");
                    } else {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("");
                    }
                    break;
                case "MZ_ShouShuBuWei":
                    if (radioSoBn0301.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("1");
                    } else if (radioSoBn0302.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("0");
                    } else {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("");
                    }
                    break;
                case "MZ_ShouShuZhiQing":
                    if (radioSoBn0401.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("1");
                    } else if (radioSoBn0402.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("0");
                    } else {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("");
                    }
                    break;
                case "MZ_MaZuiZhiQing":
                    if (radioSoBn0501.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("1");
                    } else if (radioSoBn0502.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("0");
                    } else {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("");
                    }
                    break;
                case "MZ_MaZuiFangShi":
                    if (radioSoBn0601.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("1");
                    } else if (radioSoBn0602.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("0");
                    } else {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("");
                    }
                    break;
                case "MZ_MaZuiSheBeiAnQuan":
                    if (radioSoBn0701.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("1");
                    } else if (radioSoBn0702.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("0");
                    } else {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("");
                    }
                    break;
                case "MZ_PiFuWanZheng":
                    if (radioSoBn0801.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("1");
                    } else if (radioSoBn0802.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("0");
                    } else {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("");
                    }
                    break;
                case "MZ_ShuQianPiFuZhunBei":
                    if (radioSoBn0901.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("1");
                    } else if (radioSoBn0902.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("0");
                    } else {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("");
                    }
                    break;
                case "MZ_JingMaiTongDaoJianLi":
                    if (radioSoBn1001.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("1");
                    } else if (radioSoBn1002.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("0");
                    } else {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("");
                    }
                    break;
                case "MZ_HuanZheGuoMingShi":
                    if (radioSoBn1101.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("1");
                    } else if (radioSoBn1102.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("0");
                    } else {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("");
                    }
                    break;
                case "MZ_KangJunYaoWuPiShi":
                    if (radioSoBn1201.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("1");
                    } else if (radioSoBn1202.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("0");
                    } else {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("");
                    }
                    break;
                case "MZ_ShuQianBeiXue":
                    if (radioSoBn1301.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("1");
                    } else if (radioSoBn1302.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("0");
                    } else {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("");
                    }
                    break;
                case "MZ_JiaTi":
                    if (radioSoBn1401.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("1");
                    } else if (radioSoBn1402.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("0");
                    } else {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("");
                    }
                    break;
                case "MZ_TiNeiZhiRuWu":
                    if (radioSoBn1501.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("1");
                    } else if (radioSoBn1502.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("0");
                    } else {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("");
                    }
                    break;
                case "MZ_YingXiangXueZiLiao":
                    if (radioSoBn1601.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("1");
                    } else if (radioSoBn1602.isChecked()) {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("0");
                    } else {
                        AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue("");
                    }
                    break;
                case "MZ_Other":
                    AppConfig.SAFEOPERATIONBEAN.getObject().getSecurityItemList().get(i).setItemValue(edtSoBn1701.getText().toString());
                    break;
            }
        }

        if (AppConfig.SAFEOPERATIONBEAN.getObject().getSecurity().getSecurityId() == null) {
            Map<String, String> params = new HashMap<>();
            params.put("operationNo", PreferenceHelper.readString(aty, AppConfig.PATIENT_INFO, AppConfig.PATIENT_OPERATION_ID) + "");
            params.put("saveData", JSON.toJSONString(AppConfig.SAFEOPERATIONBEAN));
            presenter.insertSafeOperationDate(params);
        } else {
            Map<String, String> params = new HashMap<>();
            params.put("accountId", PreferenceHelper.readInt(aty, AppConfig.USER_INFO, AppConfig.USER_ACCOUNT) + "");
            params.put("fullName", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.USER_FULLNAME) + "");
            params.put("saveData", JSON.toJSONString(AppConfig.SAFEOPERATIONBEAN));
            presenter.updateSafeOperationDate(params);
        }

    }

    @Override
    public void insertSafeOperationDate(SubmitBean submitBean) {
        if (submitBean.getCode() == 200) {
            ViewInject.toast("保存成功");
            finish();
        } else {
            ViewInject.toast(submitBean.getDesc());
        }
    }

    @Override
    public void updateSafeOperationDate(SubmitBean submitBean) {
        if (submitBean.getCode() == 200) {
            ViewInject.toast("保存成功");
            finish();
        } else {
            ViewInject.toast(submitBean.getDesc());
        }
    }

    @Override
    public void loadingDialogStatus(int status) {
        switch (status) {
            case AppConfig.SHOW_DIALOG:
                loadingDialog.setCanceledOnTouchOutside(false);
                loadingDialog.show();
                break;
            case AppConfig.DISMISS_DIALOG:
                loadingDialog.dismiss();
                break;

        }
    }
}
